package StudentAchievementManagementSystem.mysql;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public  class MysqlUtil {
    public static Connection connection;
    public static Statement statement;
    private static ResultSet rs;

    public static Connection getConnection() throws IOException, SQLException, ClassNotFoundException {
        Properties properties = new Properties();
        properties.load(new FileInputStream("src//StudentAchievementManagementSystem//mysql//mysql.properties"));
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
        String driver = properties.getProperty("driver");
        String url = properties.getProperty("url");

        Connection connection = DriverManager.getConnection(url, user, password);

        return connection;
    }
    public static void close() throws SQLException {
        if (rs != null) {
            rs.close();
        }
        if (statement != null) {
            statement.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
